<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
      :selectionType="'single'"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)" :disabled="isOpen">确 定</multiuse-button>
    </div>
  </div>
</template>
<script>
import { fpList,getNotPage,gettmFiAccountType,confirmAutowiredPerson } from '@/api/omSale/HeadquartersInventory/HeadquartersResources';
import { dictionary } from '@/utils/dictMixin';
export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        productCode:this.rowData.productCode,
        type:'logisticsChanges'
      },
      fetchApi: fpList,
      selectList: [],
      isOpen: true
    };
  },
  props: ['rowData'],
  mixins: [dictionary],
  created(){
    this.gettmFiAccountType()
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'doNo',
          placeholder: '请输入',

        },
        {
          type: 'INPUT',
          label: '订货单编号',
          fieldName: 'orderNo',
          placeholder: '请输入',

        },
        {
          type: 'SELECT',
          label: '资金类型',
          fieldName: 'accountType',
          placeholder: '请选择',
          itemList:[],

        },

        {
          type: 'SELECT',
          label: '所属公司',
          fieldName: 'powerCompany',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        },

        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '请选择',
          itemList:this.createDictList('6006'),
          change:p=>{
            if(p){
              this.topFilterList.find(x=>x.fieldName=='orderDetailType').itemList=[];
              this.topFilterList.find(x=>x.fieldName=='orderDetailType').initialValue='';
              this.getNotPage(p)
            }else{
              this.topFilterList.find(x=>x.fieldName=='orderDetailType').itemList=[];
              this.topFilterList.find(x=>x.fieldName=='orderDetailType').initialValue='';
            }
          }
        },
        {
          type: 'SELECT',
          label: '订单类型细分',
          fieldName: 'orderDetailType',
          placeholder: '请选择',
          itemList:[]
        },

        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '外饰颜色名称',
          fieldName: 'colorName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '内饰颜色名称',
          fieldName: 'trimName',
          placeholder: '请输入',
        },
        {
          type: 'RANGE_DATE',
          label: '提报日期',
          fieldName: 'reportDateBegin|reportDateEnd',
          placeholder: '请选择',
          initialValue:[],
          dateType:'exactdaterange'
        },
        {
          type: 'RANGE_INPUT_NUMBER',
          label: '折后单价',
          fieldName: 'afterDiscountAmountMin|afterDiscountAmountMax',
        },

      ];
    },
    createdTable() {
      return [
        {
          title: '事业部',
          dataIndex: 'deptName',
          sorter: true,
          filter: true,
          filterType: 'input',

        },
        {
          title: '办事处',
          dataIndex: 'officeName',
          sorter: true,
          filter: true,
          filterType: 'input',

        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '订货单编号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'center',
          width: 200
        },
        {
          title: '销售订单号',
          dataIndex: 'doNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'center',
          width: 200
        },
        {
          title: '订单类型',
          dataIndex: 'orderType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6006'),
          render: (p) => {
            return <span >{this.createDictText(p.row.orderType, '6006')}</span>;
          },
        },
        {
          title: '订单细分类型',
          dataIndex: 'orderDetailTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '订单状态',
          dataIndex: 'orderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6002'),
          render: (p) => {
            return <span >{this.createDictText(p.row.orderStatus, '6002')}</span>;
          },
        },
        {
          title: '资金类型',
          dataIndex: 'accountType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType:'select',
          editItems:[]
        },
        {
          title: '订单年月',
          dataIndex: 'orderYearMonth',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '收车地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '可用资源',
          dataIndex: 'avilableVehicles',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '要求交付日期',
          dataIndex: 'requiredDeliveryDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '市场指导价',
          dataIndex: 'singleAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '国补金额',
          dataIndex: 'subsidyAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣金额',
          dataIndex: 'discountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣率(%)',
          dataIndex: 'discount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否使用返利',
          dataIndex: 'isRebate',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: (p) => {
            return <span >{this.createDictText(p.row.isRebate, '1004')}</span>;
          },
        },
        {
          title: '折后单价',
          dataIndex: 'afterDiscountAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '账户可用余额',
          dataIndex: 'availableAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '运输方式',
          dataIndex: 'transportType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6004'),
          render: (p) => {
            return <span >{this.createDictText(p.row.transportType, '6004')}</span>;
          },
        },
        {
          title: '提报时间',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审核时间',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
      ];
    },
    changeHandle(val) {

      val.productCode = this.rowData.productCode;
      let json=JSON.parse(JSON.stringify(val))
      this.isOpen = true;
      this.fetchParams = Object.assign({}, json);
    },
    async getNotPage(orderType) {
      let list = await getNotPage({ orderType: orderType });
      this.topFilterList.map(x => {
        if (x.fieldName == 'orderDetailType') {
          x.itemList = list.data.map(x => ({ text: x.subName, value: x.subId }));
        }
      });
    },
    async gettmFiAccountType(){
      let res=(await gettmFiAccountType({fundsType:0})).data.map(x=>({text:x.accountTypeName,value:x.id}))
      this.columns.find(x=>x.dataIndex=='accountType').editItems=res;
      this.columns.find(x=>x.dataIndex=='accountType').filterItems=res;
      this.topFilterList.find(x=>x.fieldName=='accountType').itemList=res;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        debugger
        if(this.selectList.length>0){
           let json={
              vehicleId:this.rowData.id,
              id:this.selectList[0].id
            }
          let res=await confirmAutowiredPerson(json)
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '配车成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }

        }
    },
    selectChangeHandle(val) {
      if (val.length > 0) {
        this.selectList = val;
        this.isOpen = false;
      } else {
        this.isOpen = true;
        this.selectList = [];
      }
    }
  }
};
</script>
